﻿using System;
using Microsoft.Xna.Framework;

namespace LevelEditor
{
    public class TerrainRule
    {
        public RuleType type;

        public bool exclusive = true;

        /// <summary>
        /// Gets or sets the values of this rule, return type changes based on what type of rule this is
        /// </summary>
        public object Value
        {
            get
            {
                switch (type)
                {
                    case RuleType.AboveAltitude:
                        return altitude;
                    case RuleType.AltitudeRange:
                        return minMaxAltitude;
                    case RuleType.BelowAltitude:
                        return altitude;
                    case RuleType.FacesDirection:
                        return direction;
                    case RuleType.Underwater:
                        return true;

                }

                return null;
            }

            set
            {
                switch (type)
                {
                    case RuleType.AltitudeRange:
                        minMaxAltitude = (Vector2)value;
                        break;
                    case RuleType.AboveAltitude:
                        altitude = (float)value;
                        break;
                    case RuleType.FacesDirection:
                        direction = (Vector4)value;
                        break;
                    case RuleType.BelowAltitude:
                        altitude = (float)value;
                        break;
                }
            }
        }

        /// <summary>
        /// { x, y, z } = direction { w } = bias
        /// </summary>
        Vector4 direction;
        
        float altitude;

        /// <summary>
        /// Used to store min and max altitude if this is a 'AltitudeRange' type rule
        /// </summary>
        Vector2 minMaxAltitude;

        public TerrainRule()
        {
            type = RuleType.None;
        }

        public TerrainRule(RuleType type, object value)
        {
            this.type = type;
            this.Value = value;
        }

        public override string ToString()
        {
            return type.ToString();
        }
    }
}